/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

//Include library header

#include "common.h"

namespace tri{

void bindImage( std::string _image,tri::TTexture* tex){
	if (_image.compare("")!=0) {
		tex = tri::getTexture(_image);

		if (tex!=NULL) {
			if (!tex->created()) {
				tex->load(_image);
			}
			tex->bind();
		} else if (tri::sys::isFile(_image)) {
			tri::createTexture(_image);
			tex = tri::getTexture(_image);
			if (tex!=NULL) {
				tex->load(_image);
				tex->bind();
			}

		} else {
			tri::unbindAllTextures();
		}

	} else {
		tri::unbindAllTextures();
	}
}

void bindImage(std::string _image){
	tri::TTexture* tex = NULL;
	if (_image.compare("")!=0) {
		tex = tri::getTexture(_image);

		if (tex!=NULL) {
			if (!tex->created()) {
				tex->load(_image);
			}
			tex->bind();
		} else if (tri::sys::isFile(_image)) {
			tri::createTexture(_image);
			tex = tri::getTexture(_image);
			if (tex!=NULL) {
				tex->load(_image);
				tex->bind();
			}

		} else {
			tri::unbindAllTextures();
		}

	} else {
		tri::unbindAllTextures();
	}
}

}
